//
//  ALPS_TRadioTCell.m
//  Alps
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_TRadioTCell.h"
#import "ALPS_TRadioCCell.h"
@implementation ALPS_TRadioTCell

- (void)dealloc
{
    _collectionView.delegate = nil;
    _collectionView.dataSource = nil;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.triangleView = [[UIImageView alloc] init];
        self.triangleView.image = [UIImage imageNamed:@"toolbar_play_n"];
        [self.contentView addSubview:_triangleView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.text = @"推荐";
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_titleLabel];
        
        self.moreLabel = [[UILabel alloc] init];
        self.moreLabel.text = @"更多";
        self.moreLabel.font = [UIFont systemFontOfSize:15];
        self.moreLabel.textAlignment = 2;
        self.moreLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_moreLabel];
        
        self.arrowView = [[UIImageView alloc] init];
        self.arrowView.image = [UIImage imageNamed:@"xm_accessory"];
        [self.contentView addSubview:_arrowView];
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(ScreeWidth, 100);
        flowLayout.minimumLineSpacing = 0;
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        
        self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, ScreeWidth, 300) collectionViewLayout:flowLayout];
        self.collectionView.dataSource = self;
        self.collectionView.delegate = self;
        self.collectionView.scrollEnabled = NO;
        [self.contentView addSubview:_collectionView];
        self.collectionView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.00];
        [self.collectionView registerClass:[ALPS_TRadioCCell class] forCellWithReuseIdentifier:@"cell"];
        
        
        self.underlineLabel = [[UILabel alloc] init];
        self.underlineLabel.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
        [self.contentView addSubview:_underlineLabel];
        
        
    }


    return self;
}

-(void)layoutSubviews
{

    [super layoutSubviews];
    [self.underlineLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(0);
        make.height.equalTo(10);
        make.width.equalTo(self.contentView);
    }];
    
    [self.triangleView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(5);
        make.left.equalTo(self.contentView).offset(0);
        make.width.equalTo(50);
        make.height.equalTo(50);
        
        
    }];
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.underlineLabel.bottom).offset(5);
        make.left.equalTo(self.triangleView.right).offset(5);
        make.width.equalTo(100);
        make.height.equalTo(30);
    
    }];
    
    [self.moreLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.underlineLabel.bottom).offset(10);
        make.right.equalTo(self.contentView).offset(-30);
        make.width.equalTo(30);
        make.width.equalTo(30);
        
    }];
    
    [self.arrowView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.underlineLabel.bottom).offset(13);
        make.right.equalTo(self.contentView).offset(-10);
        make.width.equalTo(7);
        make.height.equalTo(14);
    }];

}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    return self.dataSource.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ALPS_TRadioCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.model = [self.dataSource objectAtIndex:indexPath.row];
    return cell;

}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    self.radioValue(indexPath.row);

}


-(void)setDataSource:(NSMutableArray *)dataSource
{
    if (_dataSource != dataSource) {
        _dataSource = dataSource;
    }
    [self.collectionView reloadData];

}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
